package bookez.model.businessobject;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@NamedQueries({
        @NamedQuery(name = "TripSchedule.findAll",
                query = "from TripSchedule"),
        @NamedQuery(name = "TripSchedule.findByTripCode",
                query = "from TripSchedule as ts where ts.tripCode = :tripCode")
})


@Entity
@Table(name = "trip")
public class TripSchedule extends BusinessObject implements Serializable {

    public static class NamedQueries {
        public static final String FIND_ALL = "TripSchedule.findAll";
        public static final String FIND_BY_TRIP_CODE = "TripSchedule.findByTripCode";
    }
    

    @Id
    @GeneratedValue
    public Long getId() {
        return this.id;
    }

    public void setId(Long value) {
        this.id = value;
    }

    @Column(name = "trip_code", nullable = false)
    public String getTripCode() {
        return this.tripCode;
    }

    public void setTripCode(String value) {
        this.tripCode = value;
    }

    @Column(name = "departure_time", nullable = false)
    public Date getDepartureTime() {
        return makeCopyOfDate(this.departureTime);
    }
    
    private static Date makeCopyOfDate(Date source) {
        return new Date(source.getTime());
    }

    public void setDepartureTime(Date value) {
        this.departureTime = makeCopyOfDate(value);
    }

    @Column(name = "starting_date", nullable = false)
    public Date getStartingDate() {
        return startingDate;
    }

    public void setStartingDate(Date startingDate) {
        this.startingDate = startingDate;
    }

    @Column(name = "ending_date", nullable = false)
    public Date getEndingDate() {
        return endingDate;
    }

    public void setEndingDate(Date endingDate) {
        this.endingDate = endingDate;
    }

    @Column(name = "boarding_point", nullable = false)
    public String getBoardingPoint() {
        return this.boardingPoint;
    }

    public void setBoardingPoint(String value) {
        this.boardingPoint = value;
    }

    @Column(name = "dropping_point", nullable = false)
    public String getDroppingPoint() {
        return this.droppingPoint;
    }

    public void setDroppingPoint(String value) {
        this.droppingPoint = value;
    }

    @Column(name = "fare", nullable = false)
    public BigDecimal getFare() {
        return this.fare;
    }

    public void setFare(BigDecimal value) {
        this.fare = value;
    }

    @ManyToOne(cascade = { CascadeType.PERSIST })
    @JoinColumn(name = "route_id", nullable = false)
    public Route getRoute() {
        return this.route;
    }

    public void setRoute(Route value) {
        this.route = value;
    }

    @ManyToOne(cascade = { CascadeType.PERSIST })
    @JoinColumn(name = "bustype_id", nullable = false)
    public BusType getBusType() {
        return this.busType;
    }

    public void setBusType(BusType value) {
        this.busType = value;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "schedule")
    public List<TripDailyRecord> getDailyRecords() {
        return this.dailyRecords;
    }

    public void setDailyRecords(List<TripDailyRecord> value) {
        this.dailyRecords = value;
    }

    @Enumerated(EnumType.STRING)
    public TripStatus getStatus() {
        return this.status;
    }

    public void setStatus(TripStatus value) {
        this.status = value;
    }

    @Override
    protected boolean blindlyEquals(Object obj) {
        // TODO Auto-generated method stub
        if (!(obj instanceof TripSchedule)) {
            return false;
        }
        // Check business keys
        final TripSchedule other = (TripSchedule) obj;

        boolean tripCodeChecked = checkProperty(this.getTripCode(),
                other.getTripCode());

        return processResult(new boolean[] { tripCodeChecked });
    }// end method blindlyEquals

    @Override
    public int hashCode() {
        // TODO Auto-generated method stub
        addPropertyToHashCode(getTripCode());
        return toHashCode();
    }// end method hashCode

    @Override
    public String toString() {
        // TODO Auto-generated method stub
        addInfo("id", getId());
        addInfo("tripCode", getTripCode());
        addInfo("departureTime", getDepartureTime());
        addInfo("boardingPoint", getBoardingPoint());
        addInfo("droppingPoint", getDroppingPoint());
        addInfo("fare", getFare());
        addInfo("route", getRoute());
        addInfo("busType", getBusType());
        addInfo("tripStatus", getStatus());
        return createInfo();
    }// end method toString

    // Instance variables
    private Long id;
    private String tripCode;
    private Date departureTime;
    private Date startingDate;
    private Date endingDate;
    private String boardingPoint;
    private String droppingPoint;
    private BigDecimal fare;
    private Route route;
    private BusType busType;
    private TripStatus status;

    private List<TripDailyRecord> dailyRecords;

    private static final long serialVersionUID = -911458234779365875L;
}// end class TripSchedule
